﻿using Microsoft.EntityFrameworkCore;
using ProductManagement.Domain;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;

namespace ProductManagement.EntityFrameworkCore
{
    [ConnectionStringName("ProductManagement")]
    public class ProductManagementDbContext : AbpDbContext<ProductManagementDbContext>, IProductManagementDbContext
    {
        public static string TablePrefix { get; set; } = ProductManagementConsts.DefaultDbTablePrefix;

        public static string Schema { get; set; } = ProductManagementConsts.DefaultDbSchema;

        public DbSet<ProductDemo> ProductDemos { get; set; }

        public DbSet<ProAttribute> ProAttribute { get; internal set; }

        public DbSet<Category> Category { get; internal set; }
        public DbSet<ProSpec> ProSpec { get; internal set; }
        public DbSet<ProSpecValue> ProSpecValue { get; internal set; }
        public DbSet<ProChild> ProChild { get; internal set; }
        public DbSet<ProChildSpec> ProChildSpec { get; internal set; }

        public ProductManagementDbContext(DbContextOptions<ProductManagementDbContext> options)
            : base(options)
        {

        }

        protected override void OnModelCreating(ModelBuilder builder)
        {

            //参见实体配置： https://learn.microsoft.com/zh-cn/ef/core/modeling/#use-fluent-api-to-configure-a-model
            builder.ApplyConfigurationsFromAssembly(typeof(ProductManagementDbContext).Assembly);

            base.OnModelCreating(builder);

            builder.ConfigureProductManagement(options =>
            {
                options.TablePrefix = TablePrefix;
                options.Schema = Schema;
            });
        }
    }
}